<?php
    $orderContent = "<h1>Customer Order...</h1>\n";
    $counter=1;
    $orderNumber = date(Ymd_his) . "_username";
    $orderContent .= "<h3>" . $orderNumber . "</h3>";
    $orderContent .= "<table border=1>\n<tr><th>Item Name</th><th>Price</th><th>Qty.</th><th>Subtotal</th></tr>\n<tr>";
    foreach($_POST as $value)
    {
        if($counter == 4)
        {
            $orderContent .= "<td>" . $value . "</td></tr>\n";
            $counter = 1;
        }
        else
        {
            $orderContent .= "<td>" . $value . "</td>";
            $counter++;
        }
    }
    $orderContent .= "</table>"; 
    echo $orderContent;  
    $filename = "../orders/" . $orderNumber . ".html";
    $fh = fopen($filename, 'w') or die("can't open file");
    fwrite($fh, $orderContent);
    fclose($fh);
?>
